from sqlalchemy import select, desc
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.sql.functions import current_user

from auth.models import User
from salaries.models import Salary


async def get_salary(session: AsyncSession,
                     current_user: User):
    query = select(Salary).where(Salary.user_id == current_user.id).order_by(desc(Salary.id)).limit(1)
    result = await session.execute(query)
    return result.scalars().first()
